@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <h5>帮助列表</h5>
        </div>
        <div class="ibox-content">
            <a class="btn btn-primary" href="/admin/help/create">添加问题</a>
            <div class="hr-line-dashed"></div>
            <div id="tblDataList" class="tab-pane active">

            </div>
        </div>
    </div>
</div>

<script type="text/html" id="tplDataListTr">
    <table class="table table-striped table-bordered">
        <thead>
        <tr>
            <th>id</th>
            <th>标题</th>
            <th>内容</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @{{each rows.data as v i}}
        <tr data-id="@{{v.id}}" data-status="@{{v.status}}">
            <td>@{{v.id}}</td>
            <td>@{{v.title}}</td>
            <td>@{{#v.content}}</td>
            <td>
                <a href="/admin/help/edit?id=@{{v.id}}" class="btn btn-success btn-sm">
                    <i class="fa fa-edit"></i>编辑
                </a>
                <a href="javascript:;" class="btn btn-danger btn-sm btn-del">
                    <i class="fa fa-trash-o"></i>删除
                </a>
            </td>
        </tr>
        @{{/each}}
        </tbody>

    </table>
    <div class="text-center " id='pagination'></div>
</script>
@endsection

@section('pageheader')
@endsection
@section('pagescript')
<script>
    $("#side-menu li[rel='help']").addClass("active");
    var filter = {page:1,status:0};
    $(function () {
        renderList();
        $("#pagination").on("click", ".pagination a", function() {
            filter.page = $(this).attr("rel");
            renderList();
        });

        $("body").on("click",".btn-del",function(){
            var that = $(this).parents('tr').eq(0)
            var id = that.attr('data-id');
            layer.confirm('确定删除该记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.post('/admin/help/del',{'id':id},function(data){
                    layer.msg('删除成功');
                    that.remove();
                }).fail(failure);
            }, function(){
                layer.closeAll();
            });
        })

    })

    var renderList = function(){
        $("#tblDataList").html('<div><p class="ibox-loading-31">&nbsp;</p></div>');
        $.get('/admin/help/page-rows',filter,function(data){
            var pagination = data.rows;;
           $("#tblDataList").html(template("tplDataListTr", data));
            $("#pagination").html(page(pagination.last_page, pagination.total, pagination.current_page));
        }).fail(failure);
    };

</script>
@endsection
